/*
 * @Descripttion: 引入该目录下所有组件  专指引入各个子文件夹下index.vue文件
 * @version: 
 * @Author: sueRimn
 * @Date: 2022-10-14 15:54:48
 * @LastEditors: sueRimn
 * @LastEditTime: 2022-10-14 16:53:01
 */
let allComponents = {};
let rdashAlpha = /-([a-z])/ig;
const requireComponent = require.context(
  './',  // 其组件目录的相对路径
  true,  // 是否查询其子目录
  /index\.(vue)$/  // 匹配基础组件文件名的正则表达式
)
requireComponent.keys().forEach(fileName => {
  const componentConfig = requireComponent(fileName);//获取组件配置
  const componentName = upperFirst(camelCase(fileName.split("/")[1]));
  allComponents[componentName] = componentConfig.default || componentConfig;
  //当组件有重命名alias时
  if (allComponents[componentName].alias) {
    let alias = allComponents[componentName].alias;
    if (typeof alias == "string") {
      allComponents[alias] = allComponents[componentName];
    } else if (alias instanceof Array) {
      alias.forEach((item) => {
        allComponents[upperFirst(item)] = allComponents[componentName];
      })
    }
  }
});
function upperFirst(str) {
  return str.replace(str[0], str[0].toUpperCase())
}
function camelCase(str) {
  return str.replace(rdashAlpha, function (all, letter) {
    return letter.toUpperCase();
  })
}
export default allComponents